#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require_relative '../lib/shell'

def write_config
  File.write shell.expand('~/.gitconfig'), <<~END_CONFIG
    # 不同的工作目录设置不同的用户名和邮箱
    [includeIf "gitdir:~/workspace/work/"]
    	path = ~/.gitconfig-work
    [includeIf "gitdir:~/workspace/personal/"]
    	path = ~/.gitconfig-personal
    [includeIf "gitdir:~/.config/"]
    	path = ~/.gitconfig-personal

    # 显示中文路径
    [core]
    	quotepath = false
    # 设置自动保存密码在内存，且一周不失效
    ; [credential]
    ; 	helper = cache --timeout 604800
  END_CONFIG

  File.write shell.expand('~/.gitconfig-personal'), <<~END_CONFIG
    [user]
    	name = Run
    	email = run27017@126.com
  END_CONFIG

  File.write shell.expand('~/.gitconfig-work'), <<~END_CONFIG
    [user]
    	name = Run
    	email = run27017@126.com
  END_CONFIG
end

OptionParser.new do |opts|
  opts.banner = '配置 Git'

  opts.on('-c', '--config', '执行最优配置') do
    write_config
  end
end.parse!
